import {request} from "@yaf/request";
import { toApi } from "@/service/proxyApi";
import {RespDataType, RequestDataType} from "./apiType";

export * from "./apiType";
const {get, postJSON, put, del} = request;

/**
 * 获取角色分页列表数据
 */
export const getRolePageList = (params: { page: number; pageSize: number; roleName?: string }) => {
    return get<RespDataType.RolePageList>(toApi("api/v1/system/role/list"),params);
}

/**
 * 创建角色
 */
export const createRole = (params: RequestDataType.CreateRoleItem) => {
    return postJSON(toApi("api/v1/system/role/add"), params);
}

/**
 * 更新角色
 */
export const updateRole = (roleId: number, params: Partial<RequestDataType.UpdateRoleItem>) => {
    params.id = roleId;
    return put(toApi("api/v1/system/role/edit"), params);
}

/**
 * 删除角色
 */
export const delRole = (roleIdList: number[]) => {
    return del(toApi(`api/v1/system/role/delete?ids=${JSON.stringify(roleIdList)}`));
}

/**
 * 获取单个角色内容
 */
export const getRole = (roleId: number) => {
    return get<RespDataType.RoleInfo>(toApi("api/v1/system/role/get"), {id: roleId});
}

/**
 * 获取角色参数
 */
export const getRoleParams = () => {
  return get<RespDataType.RoleParams>(toApi("api/v1/system/role/getParams"));
}

/**
 * 更新数据权限
 */
export const updateRoleDataScope = (roleId: number, params: { roleId?: number, dataScope: number, deptIds?: number[] }) => {
    params.roleId = roleId;
    return put(toApi("api/v1/system/role/dataScope"), params);
}

/**
 * 获取角色的自定义数据范围
 */
export const getRoleDeptCustomDataScope = (roleId: number) => {
    return get<RespDataType.RoleSelectedCustomDataScope>(toApi("api/v1/system/role/deptTreeSelect/"), {roleId});
}

